﻿define(function (require) {

    var GroupView = require('views/group.view');
    var utility = require('utility/utility');

    return Backbone.View.extend({
        tagName: "ul",
        events: {

    },
    render: function () {
        this.date = null;
        this.model.each(this.addOne);
    },
    initialize: function () {
        $(this.el).addClass('group-list ui-listview')
                  .attr({
                      "data-role": "listview",
                      "data-split-icon": "gear",
                      "data-split-theme": "d",
                      "data-filter": true,
                      "data-filter-placeholder": "Search group..."
                  });

        _.bindAll(this, 'addOne', 'render', 'getGroups');
        this.model.bind('getAll', this.render);
    },
    render: function () {
        this.model.each(this.addOne);
    },
    addOne: function (e) {
        var view = new GroupView({ model: e });
        var element = view.render().el;
        $(this.el).append(element);
    },
    getGroups: function () {
        var models = this.model.getGroups();
        var groups = [];
        for (var key in models) {
            groups.push(_.clone(models[key].attributes))
        }
        return groups;
    },
    resetModels: function () {
        this.model.resetModels();
    },
    clear: function (e) {

    }

});

});